package top.littlejiang.onlinexam.controller;

import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.littlejiang.onlinexam.common.annotation.Log;
import top.littlejiang.onlinexam.common.utils.JWTUtils;
import top.littlejiang.onlinexam.common.utils.Result;
import top.littlejiang.onlinexam.entity.OlexamExamWork;
import top.littlejiang.onlinexam.service.OlexamExamWorkService;

/**
 * @author chen
 * @Description
 * @since 2021/4/10 14:16
 */
@Controller
@RequestMapping("/examwork")
public class ExamWorkController {

    @Autowired
    OlexamExamWorkService workService;

    /**
     * 获取考试
     * @param query
     * @return
     */
    @Log("进入监考/阅卷")
    @PostMapping("/getexams")
    @ResponseBody
    @RequiresPermissions("olexam:exam:proctor")
    public Result getExams(@RequestBody OlexamExamWork query){
        query.setFkUserId(JWTUtils.getUserId());
        return Result.ok(workService.selectByUser(query));
    }

    /**
     * 获取监考的学生
     * redis -》 tolist
     * @param param
     * @return
     */
    @PostMapping("/getstudents")
    @ResponseBody
    @RequiresPermissions("olexam:exam:proctor")
    public Result getStudents(@RequestBody JSONObject param){
        return Result.ok(workService.getStudents(param.getString("examUuid")));
    }
}
